const app = getApp()
var stylecss = require('../../utils/stylecss.js');
Component({
    properties: {
      scrollTop: {
        type: Number,
        observer: function(newVal, oldVal) {
          this.updatscroll()
        }
      },
        block_id:String,
        num:Number,
        item: {
            type: Object,
            observer: function(newVal, oldVal) {
              this.updateRate()
            }
          }
      },
    data: {
        styleType:'style1',
        anima:''
    },
    lifetimes: {
      ready: function() {
        let that = this;
        const query = wx.createSelectorQuery().in(this)
        setTimeout(() => { 
           query.select('#'+this.data.item.id).boundingClientRect(res=>{
                that.setData({
                  top:res.top
                })
              }).exec();
         }, 0);
       },
        attached: function () { 
           
        }
      },
    methods: {
      updatscroll:function(){
        var nowtop=this.data.scrollTop-this.data.top
        var oldanima=this.data.oldanima
        if(nowtop<=0){
         this.setData({
           anima:oldanima
         })
        }else{
          this.setData({
              anima:''
          })
        }
     },
        updateRate:function(){
            var css=stylecss.css(this.data.item.id);
            var anima=stylecss.animated(this.data.item.id);
            this.setData({
              oldanima:anima,
              anima:anima,
              css:css
            })
        }
          
    }
});
